# Maintainer:: Tim Meusel <tim@bastelfreak.de>

_gemname=metaclass
pkgname="ruby-${_gemname}"
pkgver=0.0.4
pkgrel=1
pkgdesc='Dynamic inspection of the hierarchy of method definitions on a Ruby object.'
arch=('any')
url="https://github.com/floehopper/${_gemname}"
license=('MIT')
depends=('ruby')
checkdepends=('ruby-rake')
makedepends=('ruby-minitest' 'ruby-test-unit')
options=('!emptydirs')
source=("${pkgname}-${pkgver}.tar.gz::${url}/archive/v${pkgver}.tar.gz")
sha512sums=('5f41fe3db9c682ab6ab01c737c8531d2b4c2fdbc0f35f8fc9f40ce09a84ddf0d442c17caa1c3e87bb2c5e4703556c5d50fd9f72434b89e03d163db375046f0a4')

prepare() {
  cd "${_gemname}-${pkgver}"

  # `git` doesn't work within src dir, because we downloaded an archive
  sed --in-place 's|git ls-files|find|' ${_gemname}.gemspec
  sed --in-place '/s.test_files/d' ${_gemname}.gemspec
  sed --in-place '/s.executables/d' ${_gemname}.gemspec

  # Disable bundler loading (useless dependency)
  sed --in-place '/bundler/d' Rakefile test/test_helper.rb

  # Disable deprecated gemspec option
  sed --in-place '/s.rubyforge_project/d' ${_gemname}.gemspec
}

check() {
  cd "${_gemname}-${pkgver}"
  rake test
}

build() {
  cd "${_gemname}-${pkgver}"
  gem build ${_gemname}.gemspec
}

package() {
  cd "${_gemname}-${pkgver}"
  local _gemdir="$(gem env gemdir)"
  gem install --ignore-dependencies --no-user-install --install-dir "${pkgdir}${_gemdir}" --bindir "${pkgdir}/usr/bin" "${_gemname}-${pkgver}.gem"
  install -Dm 644 README.md --target-directory "${pkgdir}/usr/share/doc/${pkgname}"
  install -Dm 644 COPYING.txt --target-directory "${pkgdir}/usr/share/licenses/${pkgname}"

  # delete unneeded files
  rm "${pkgdir}/${_gemdir}/cache/${_gemname}-${pkgver}.gem"
  rm -rf "${pkgdir}/${_gemdir}/gems/${_gemname}-${pkgver}/"{test,yard-templates,gemfiles,bin,.github,.gemtest,mocha.gemspec.orig}
}

# vim: ts=2 sw=2 et:
